Skip to content

[ScalarizeShapes] Fold select.int through cat in shape computations#4513

Merged
zjgarvey merged 2 commits into
llvm:mainfrom
jtuyls:shape-gather-to-size-int
May 13, 2026
Merged

[ScalarizeShapes] Fold select.int through cat in shape computations#4513
zjgarvey merged 2 commits into
llvm:mainfrom
jtuyls:shape-gather-to-size-int

Conversation

@jtuyls
Copy link
Copy Markdown
Contributor

@jtuyls jtuyls commented Mar 24, 2026

Extend getListFromTensor to recurse into aten.cat operands and add a select.int folding pattern. This resolves shape elements from concat-based shape tensors used by onnx.Reshape lowering.

Extend getListFromTensor to recurse into aten.cat operands and add
a select.int folding pattern. This resolves shape elements from
concat-based shape tensors used by onnx.Reshape lowering.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jtuyls jtuyls requested review from rsuderman and zjgarvey March 24, 2026 10:29
Copy link
Copy Markdown
Collaborator

@zjgarvey zjgarvey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the extremely late review. This somehow got dropped from my queue after I went to look back at the prim op. I just have the one concern about the prim op being expected to return rank 0 sometimes, but otherwise this looks good to me.

Comment thread lib/Dialect/Torch/Transforms/ScalarizeShapes.cpp Outdated
…eplacement

Address review: prim.NumToTensor.Scalar's abstract-interp shape function
returns []. Constructing it with a non-rank-0 result type (as it would be
when aten.select.int produces a [1] tensor in ONNX->Torch lowering) leaves
its SSA type inconsistent with the shape contract.

Build the NumToTensor with an explicit rank-0 type. When the original
select.int result is non-rank-0, recover the shape via aten.unsqueeze.
getListFromTensor already pattern-matches unsqueeze(NumToTensor(scalar)),
so downstream propagation patterns still see straight through; the helper
+ RemoveUnusedPattern entries reclaim the intermediates after item folds.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jtuyls jtuyls force-pushed the shape-gather-to-size-int branch from 0365566 to 21dc832 Compare May 13, 2026 11:37
Copy link
Copy Markdown
Collaborator

@zjgarvey zjgarvey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@zjgarvey zjgarvey merged commit 90fc215 into llvm:main May 13, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants